home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / startrek / trek73 / src / strat1.c < prev    next >
C/C++ Source or Header  |  1995-04-11  |  9KB  |  366 lines

  1. /*
  2.  * TREK73: strat1.c
  3.  *
  4.  * Standard Enemy Strategy
  5.  *
  6.  * standard_strategy
  7.  *
  8.  */
  9.  
  10. #include "defines.h"
  11. #include "structs.h"
  12.  
  13.  
  14. standard_strategy()
  15. {
  16.     extern    float fabs();
  17.     extern    struct ship *shiplist[];
  18.     extern    int shipnum;
  19.     extern    int defenseless;
  20.     extern  int corbomite;
  21.     extern     int surrender;
  22.     extern  int surrenderp;
  23.     extern  char captain[];
  24.     extern    char science[];
  25.     extern    char nav[];
  26.     extern  char com[];
  27.     extern    char helmsman[];
  28.     extern     char title[];
  29.     extern    char foename[];
  30.     extern    char foerace[];
  31.     extern    int global;
  32.     extern    char empire[];
  33.     int    i;
  34.     register struct ship *sp;
  35.     register struct ship *fed;
  36.     int    bear;
  37.     int    range;
  38.     float    tmpf;
  39.     int    loop, loop2;
  40.     int    probability;
  41.  
  42.     fed = shiplist[0];
  43.     for (i=1; i <= shipnum; i++) {
  44.         sp = shiplist[i];
  45.         if (sp->status & S_DEAD)
  46.             continue;
  47.         range = rangefind(sp->x, fed->x, sp->y, fed->y);
  48.         bear = bearing(sp->x, fed->x, sp->y, fed->y);
  49.         bear = rectify(sp->course - bear);
  50.         /*
  51.          * Take care of special commands like defenseless ruses,
  52.          * corbomite bluffs, surrenders (both sides)
  53.          */
  54.         /*
  55.          * Play dead effects
  56.          */
  57.         switch (defenseless) {
  58.         case 1: {
  59.             if (randm(10) > 2) {
  60.                 defenseless = 2;
  61.             dstrat:
  62.                 if (randm(2) == 1) {
  63.                     sp->target = NULL;
  64.                     sp->newwarp = 0.0;
  65.                 } else {
  66.                     sp->newwarp = 1.0;
  67.                 }
  68.                 printf("%s:   The %s is ",helmsman, sp->name);
  69.                 if (sp->target != NULL) {
  70.                     printf("cautiously advancing.\n");
  71.                 } else {
  72.                     printf("turning away.\n");
  73.                 }
  74.             astrat:
  75.                 if ((fabs(sp->target->warp) > 1.0)
  76.                     || (range < 200)) {
  77.                     defenseless = 6;
  78.                 } else {
  79.                     for (loop = 0; loop < 4; loop++) {
  80.                         if (sp->target->shields[loop].drain) {
  81.                             defenseless = 6;
  82.                         }
  83.                     }
  84.                 }
  85.             } else {
  86.                 printf("%s:   No apparent change in the enemy's actions.\n", helmsman);
  87.                 defenseless = 6;
  88.             }
  89.         }
  90.         break;
  91.         case 2: goto dstrat;
  92.         case 4: goto astrat;
  93.         case 5: goto astrat;
  94.         }
  95.         /*
  96.          * Corbomite bluff effects.
  97.          */
  98.         switch (corbomite) {
  99.         case 1: {
  100.             probability = 30;
  101.             if (!strcmp(foerace, "Romulan")) {
  102.                 probability = 50;
  103.             }
  104.             if (randm(100) < probability) {
  105.                 printf("%s:   %ss giving ground, Captain.  Obviously, they\n", science, foerace);
  106.                 printf("   tapped in as you expected them to.\n");
  107.                 printf("%s:  A logical assumption, Mr. %s.  Are they still\n", captain, science);
  108.                 printf("   retreating?\n");
  109.                 printf("%s:  Yes, %s\n",science, title);
  110.                 printf("%s:  Good.  All hands, stand by.\n",captain);
  111.                 corbomite = 2;
  112.             cstrat:
  113.                 sp->target = NULL;
  114.                 sp->newwarp = 3.0 + randm(7);
  115.             } else {
  116.                 printf("%s:  Message coming in from the %ss.\n",com, foerace);
  117.                 printf("%s:  Put it on audio.\n",captain);
  118.                 if (randm(2) == 1) {
  119.                     printf ("%s:  Ha, ha, ha, %s.  You lose.\n", foename, captain);
  120.                 } else {
  121.                     printf("%s:  I fell for that the last time we met, idiot!\n", foename);
  122.                 }
  123.                 corbomite = 6;
  124.             }
  125.         }
  126.         break;
  127.         case 2: goto cstrat;
  128.         case 3: if (fabs(sp->target->warp) > 2.0) {
  129.                 corbomite = 6;
  130.             }
  131.             break;
  132.         case 4: if (fabs(sp->target->warp) > 2.0) {
  133.                 corbomite = 6;
  134.             }
  135.             break;
  136.         case 5: if (fabs(sp->target->warp) > 2.0) {
  137.                 corbomite = 6;
  138.             }
  139.             break;
  140.         }
  141.         /*
  142.          * Will the enemy accept your surrender?
  143.          */
  144.          
  145.         if (surrender)
  146.             switch (surrender) {
  147.             case 1: {
  148.                 probability=49;
  149.                 if (!strcmp(foerace, "Romulan")) {
  150.                     probability = 4;
  151.                     printf("%s:  The %ss do not take prisoners.\n", nav, foerace);
  152.                 }
  153.                 if (randm(100) < probability) {
  154.                     if (randm(2) == 1) {
  155.                         printf("%s:  Prepare to die, Chicken %s!\n", foename, captain);
  156.                     } else {
  157.                         printf("%s:  No reply from the %ss.\n",com, foerace);
  158.                     }
  159.                     surrender = 6;
  160.                 } else {
  161.                     printf("%s:  Message coming in from the %s.\n", com, sp->name);
  162.                     printf("%s:  On behalf of the %s %s, I accept your surrender.\n", foename, foerace, empire);
  163.                     printf("   You have five seconds to drop your shields, cut\n");
  164.                     printf("   warp, and prepare to be boarded.\n");
  165.                     surrender = 2;
  166.                     global |= F_SURRENDER;
  167.                 sstrat:
  168.                     sp->target = fed;
  169.                     sp->newwarp = 2.0;
  170.                 }
  171.                 break;
  172.             }
  173.             case 2:
  174.             case 3: {
  175.                 warn(3);
  176.                 goto sstrat;
  177.             }
  178.             case 4:
  179.             case 5: {
  180.                 for (loop = 0; loop < 4; loop++) {
  181.                     if (sp->target->shields[loop].attemp_drain)
  182.                         goto breakout;
  183.                 }
  184.                 if (range <= 1400)
  185.                     sp->newwarp = 1.0;
  186.                 if ((range > 1000) || (fabs(sp->target->warp) > 1.0)) {
  187.                     if (surrender == 5) {
  188.                         printf("%s:  Captain %s, you have not fulfilled our terms.\n", foename, captain);
  189.                         printf("  We are resuming our attack.\n");
  190.                     }
  191.                     goto breakout;
  192.                 } else {
  193.                     fed->status |= S_SURRENDER;
  194.                     final(3);
  195.                 }
  196.             }
  197.             default: global &= ~F_SURRENDER;
  198.                 break;
  199.             breakout:
  200.                 break;
  201.             }
  202.         /*
  203.          * Enemy surrenders?
  204.          */
  205.         switch (surrenderp) {
  206.             case 1:
  207.             for (loop = 1; loop < shipnum; loop++)
  208.                 if (!(sp->status & S_ENG) && (sp->crew > 100)) {
  209.                     printf("%s:   You must be joking, Captain %s.  Why don't you\n", foename, captain);
  210.                     printf("   surrender?\n");
  211.                     surrenderp = 6;
  212.                     break;
  213.                 }
  214.             if (loop = shipnum) {
  215.                 probability = 49;
  216.                 if (!strcmp (foerace, "Romulan"))
  217.                     probability = 4;
  218.                 if (randm(100) < probability) {
  219.                     printf("%s:  As much as I hate to, Captain %s, we will surrender.\n", foename, captain);
  220.                     printf("   We are dropping shields.  You may board us.\n");
  221.                     surrenderp = 2;
  222.                 dropshields:
  223.                     for (loop = 0; loop < 3; loop++)
  224.                         sp->shields[0].drain = 0;
  225.                     sp->newwarp = 0.0;
  226.                     for (loop = 1; loop < shipnum; loop++)
  227.                         shiplist[loop]->status |= S_SURRENDER;
  228.                     global |= E_SURRENDER;
  229.                 } else {
  230.                     printf("%s:   You must be joking, Captain %s.  Why don't you\n", foename, captain);
  231.                     printf("   surrender?\n");
  232.                     surrenderp = 6;
  233.                 }
  234.             }
  235.             break;
  236.         case 2:
  237.         case 3:
  238.             warn(4);
  239.             goto dropshields;
  240.         }
  241.         /*
  242.          * Unsportsmanlike firing
  243.          */
  244.         if (betw(defenseless, 0, 6) || betw(corbomite, 0, 6)
  245.             || betw(surrender, 0, 6) || betw(surrenderp, 0, 6)) {
  246.             for (loop = 0; loop < 4; loop++)
  247.                 if (fed->phasers[i].status & P_FIRING)
  248.                     break;
  249.             for (loop2 = 0; loop2 < 6; loop2++)
  250.                 if (fed->tubes[i].status & T_FIRING)
  251.                     break;    
  252.             /* Has he fired? */
  253.             if ((loop != 4) || (loop2 != 6)) {
  254.                 /* Yes, be angry and disbelieve everything from now on */
  255.                 printf("%s: How dare you fire on us!  We are\n", foename);
  256.                 printf("  resuming our attack!\n");
  257.                 global = NORMAL;
  258.                 if (betw(defenseless,0,6))
  259.                     defenseless = 6;
  260.                 if (betw(corbomite,0,6))
  261.                     corbomite = 6;
  262.                 if (betw(surrender,0,6))
  263.                     surrender = 6;
  264.                 if (betw(surrenderp,0,6))
  265.                     surrenderp = 6;
  266.                 for (loop = 0; loop < shipnum; loop++)
  267.                     shiplist[loop]->status &= ~S_SURRENDER;
  268.             }
  269.         }
  270.         if ((global & F_SURRENDER) || (global & E_SURRENDER))
  271.             continue;
  272.         /*
  273.          * short range? 
  274.          *   1). fire phasers
  275.          *   2). lock phasers
  276.          *   3). evade probes
  277.          *   4). enemy to the rear - turn around
  278.          *   5). launch a probe?
  279.          *   6). self destruct?
  280.          *   7). set course.
  281.          */
  282.         if (range < 1050) {
  283.             if (e_closetorps(sp, fed))
  284.                 continue;
  285.             if (e_lockphasers(sp, fed))
  286.                 continue;
  287.             if (e_phasers(sp, fed))
  288.                 continue;
  289.             if (e_checkprobe(sp))
  290.                 continue;
  291.             if (bear > 90 && bear < 270) {
  292.                 e_pursue(sp, fed, 1);
  293.                 continue;
  294.             }
  295.             if (bear > 90 && bear < 270 && e_launchprobe(sp, fed))
  296.                 continue;
  297.             if (sp->pods<20 && sp->regen < 4.0 && e_destruct(sp))
  298.                 continue;
  299.             /*
  300.              * set course?
  301.              */
  302.             tmpf = fabs(fed->warp);
  303.             if (sp->target != fed || sp->warp + tmpf > 2.0) {
  304.                 e_pursue(sp, fed, (int)tmpf);
  305.                 continue;
  306.             }
  307.         }
  308.         if (range < 3800) {
  309.             /*
  310.              * either medium range, or we can't figure out what
  311.              * to do at short range
  312.              */
  313.             if (e_torpedo(sp))
  314.                 continue;
  315.             if (e_locktubes(sp, fed))
  316.                 continue;
  317.             /*
  318.              * should we run away; can we?
  319.              */
  320.             if (e_checkarms(sp) < randm(3)) {
  321.                 e_runaway(sp, fed);
  322.                 continue;
  323.             }
  324.             /*
  325.              * pursued from behind, low power: jettison engineering!
  326.              */
  327.             if (sp->energy<10 && sp->regen < 4.0 && e_jettison(sp))
  328.                 continue;
  329.             /*
  330.              * put in other junk later
  331.              */
  332.         }
  333.         /*
  334.          * either distant range, or we can't figure out
  335.          * what to do at medium range
  336.          */
  337.         if (fed->delay < 15*10 && (sp->status & S_WARP)) {
  338.             e_runaway(sp, fed);
  339.             continue;
  340.         }
  341.         /*
  342.          * enemy behind us?  make a quick turn.
  343.          */
  344.         if (bear > 135 && bear < 225) {
  345.             e_pursue(sp, fed, 1);
  346.             continue;
  347.         }
  348.         /*
  349.          * attack?
  350.          */
  351.         if (sp->pods > 40 && e_attack(sp, fed))
  352.             continue;
  353.         if (sp->energy > 30 && sp->pods > 40)
  354.             if (e_loadtubes(sp))
  355.                 continue;
  356.         if (e_locktubes(sp, fed))
  357.             continue;
  358.         if (e_lockphasers(sp, fed))
  359.             continue;
  360.         /*
  361.          * gee, there's nothing that we want to do!
  362.          */
  363.         printf("%s:  We're being scanned by the %s\n", science, sp->name);
  364.     }
  365. }
  366.